using UnityEngine;

public class BtnDistrictLoadCity : ActivatableButton
{
	[SerializeField]
	private MapDistrict district;

	[SerializeField]
	private UIButton button;

	[SerializeField]
	private UISprite sprite;

	public Color currentColor = Color.white;

	private void Awake()
	{
		district = GetComponentInParent<MapDistrict>();
		ReputationInterfaceController.networkAvailable += SwitchInternetSate;
		button = GetComponent<UIButton>();
		if (button != null && button.tweenTarget != null)
		{
			sprite = button.tweenTarget.GetComponent<UISprite>();
		}
		SwitchInternetSate(PhotonNetwork.connected);
	}

	private void OnEnable()
	{
		UpdateColor();
	}

	private void UpdateColor()
	{
		if (sprite != null)
		{
			sprite.color = currentColor;
		}
		if (button != null)
		{
			button.defaultColor = currentColor;
			button.UpdateColor(true);
		}
	}

	public void SwitchInternetSate(bool active)
	{
		if (active)
		{
			currentColor = Color.white;
		}
		else
		{
			currentColor = Color.grey;
		}
		UpdateColor();
	}

	private void OnDestroy()
	{
		ReputationInterfaceController.networkAvailable -= SwitchInternetSate;
	}

	public void OnClick()
	{
		if (controllerMenu.thisScript != null && !PhotonNetwork.connected)
		{
			ReputationInterfaceController.instance.ShowNoInternet();
			return;
		}
		settings.SetAreaNameForRespawn(district.levelscene);
		district.LoadCity();
	}
}
